<template>
  <div>
    <TopFilter ref="form" :list="form" :cols="3" :labelWidth="'85'" @filterChange="changeHandle" />
    <FilterTable
      ref="table2"
      columnsRef="partPartInventoryPartOverflowInventoryListSelection"
      height="280"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
    ></FilterTable>
    <div class="btnWrap">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" :loading="addBtnState" @click.once="saveDialog">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { searchInventoryList } from '@/api/part/partInventory/partOverflow';
import { getDealerUser } from '@/api/customerRepair/customerComplaint/customerComplaintReception';
export default {
  name: 'inventoryListSelection',
  mixins: [dictionary],
  props: {
    ptype: String
  },
  data() {
    // this.BaseTable = null;
    return {
      columns: this.createTableColumns(),
      form: this.createTopFilterList(),
      fetchApi: searchInventoryList, // 调用接口
      fetchParams: {
        sort: 'INVENTORY_NO',
        order: 'asc',
        ptype: this.ptype
      },
      selectedRows: [],
      addBtnState: null,
      salerList: {}
    };
  },
  created() {
    this.$nextTick(() => {
      this.getSalerList();
    });
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '盘点单号',
          fieldName: 'inventoryNo',
          initialValue: this.inventoryNo
        },
        {
          type: 'RANGE_DATE',
          label: '盘点日期',
          fieldName: 'innerStr|innerEnd'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '盘点单号',
          dataIndex: 'INVENTORY_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '盘点日期',
          dataIndex: 'INVENTORY_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd',
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '经手人',
          dataIndex: 'HANDLER',
          sorter: true,
          render: params => {
            return <span>{this.salerList[params.row.HANDLER]}</span>;
          },
          filterType: 'input'
        },
        {
          title: '操作员',
          dataIndex: 'operator',
          sorter: true,
          render: params => {
            return <span>{this.salerList[params.row.operator]}</span>;
          },
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
        // {
        //   title: '锁定人',
        //   dataIndex: 'LOCK_USER',
        //   sorter: true,
        //   render: params => {
        //     return <span>{this.salerList[params.row.LOCK_USER]}</span>;
        //   },
        //   filter: true,
        //   filterType: 'input'
        // }
      ];
    },
    // 选中
    selectChange(rows) {
      this.selectedRows = rows;
    },
    // searchSalesPart(val) {
    //   const params = Object.assign({}, val, { offset: 0, xhrAbort: false });
    //   this.fetchParams = params;
    // },
    // 查询
    // queryClick() {
    //   this.$refs.formPanel.SUBMIT_FORM();
    // },
    // 重置
    // resetClick() {
    //   this.$refs.formPanel.RESET_FORM();
    // },
    changeHandle(val) {
      console.log(val, 'val');
      let obj = _.cloneDeep(val);
      if (obj.innerStr) {
        obj.benginDate = obj.innerStr.substr(0, 10);
      }
      if (obj.innerEnd) {
        obj.endDate = obj.innerEnd.substr(0, 10);
      }
      console.log(obj, 'obj');
      this.fetchParams = Object.assign({}, obj, { ptype: this.ptype });
    },
    saveDialog() {
      if (this.selectedRows.length) {
        this.$emit('getInventoryId', this.selectedRows[0]);
      }
      this.$emit('close', false);
    },
    // async saveDialog() {
    //   if (this.onChangeColumn.length) {
    //     let obj = this.onChangeColumn[0];
    //     const soNO=obj.ADJUST_OUTBOUND_NO;
    //     if(obj.LOCK_USER!=null && obj.LOCK_USER!=''){
    //          //有锁定人弹出提示
    //       return  this.$notify.warning({ title: '提示信息', message: '该单号已被'+this.onChangeColumn[0].LOCK_USER+'锁定' });
    //     }else{
    //       //没有进行单号锁定再传值
    //      let res = await isLocked(soNO);
    //      if(res.resultCode==200){
    //         this.$emit('saveDialog', this.onChangeColumn);
    //      }
    //     }
    //   }
    // },
    //  点击取消关闭窗口
    closeDialog() {
      this.$emit('close', false);
    },
    async getSalerList() {
      this.$refs.table2.START_LOADING();
      let emps = await getDealerUser();
      let obj = {};
      emps.data.map(item => {
        obj[item.userId] = item.employeeName;
      });
      this.salerList = obj;
      this.fetchParams.xhrAbort = false;
      // this.$nextTick(() => {
      //   this.fetchParams.xhrAbort = true;
      // });
      // console.log(this.salerList, '销售列表');
    }
  }
  //  mounted() {
  //   this.BaseTable = this.$refs.table.$refs.pageTable;
  // }
};
</script>
<style scoped>
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
